<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>更改密码</title>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <script th:src="@{/js/jquery-3.2.1.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <style>
        body {
            background-color: rgb(240, 242, 245);
        }
    </style>

</head>
<body>
<div th:replace="components/adminPublicComponents::topbar"></div>
<div class="col-xs-6 col-md-offset-3" style="position: relative;margin-top: 5%">
    <div th:replace="components/adminPublicComponents::message"></div>
    <div class="panel panel-primary ">
        <div class="panel-heading">
            <h3 class="panel-title">密码修改</h3>
        </div>
        <div class="input-group">
            <span id="checkPwd"></span>
        </div>
        <div class="panel-body">
            <form method="post" th:action="@{/adminRepasswdDo}" class="form-inline" id="repasswd">
                <div class="input-group">
                    <input type="password" id="oldPasswd" name="oldPasswd" placeholder="输入旧密码" class="form-control" onblur="checkAdminPwd()">
                    <input type="password" id="newPasswd" name="newPasswd" placeholder="输入新密码" class="form-control">
                    <input type="password" id="reNewPasswd" name="reNewPasswd" placeholder="再次输入新密码" class="form-control">
                    <em id="tishi" style="color: red"></em>
                    <br/>
                    <span>
                            <input type="submit" value="提交" class="btn btn-default">
            </span>
                </div>
            </form>
        </div>
    </div>
</div>

<script th:inline="javascript">
    function mySubmit(flag) {
        return flag;
    }

    $(document).keyup(function () {
        if ($("#newPasswd").val() != $("#reNewPasswd").val() && $("#newPasswd").val() != "" && $("#reNewPasswd").val() != "" && $("#newPasswd").val().length == $("#reNewPasswd").val().length) {
            $("#tishi").text("两次输入的新密码不同，请检查");
        } else {
            $("#tishi").text("");
        }
    })

    $("#repasswd").submit(function () {
        if ($("#oldPasswd").val() == '' || $("#newPasswd").val() == '' || $("#reNewPasswd").val() == '') {
            $("#tishi").text("请填写完毕后提交");
            return mySubmit(false);
        } else if ($("#newPasswd").val() != $("#reNewPasswd").val()) {
            $("#tishi").text("两次输入的新密码不同，请检查");
            return mySubmit(false);
        }
    })

    function checkAdminPwd(){
        $.post({
            url:"/checkAdminPwd",
            data:{"oldPassword": $("#oldPasswd").val()},
            success:function (data){
                if (data.oldPwd === "true"){
                    $("#checkPwd").css("color","green")
                } else {
                    $("#checkPwd").css("color","red")
                }
                $("#checkPwd").html(data.msg)
            }
        })
    }
</script>

</body>
</html>
